$(document).ready(function() {
	$("#applied").click(function() {
		var checked = $(this).attr("checked");
		if (checked) {
			$("#processed").attr("checked", "checked").attr("disabled", "disabled");
		} else {
			$("#processed").removeAttr("disabled");
		}
	});
	
	$(".filterForm select[name='type']").change(function() {
		var selectedIndex = this.selectedIndex;
		var value = new String(this.options[selectedIndex].value);
		
		if (value.toLowerCase() == "dormitory") {
			$(".filterForm :submit[name='submit']").attr("disabled", "disabled");
			$(".dormitoryInput").show();
			$("#dormitoryName").next().text("");
		} else if (value.toLowerCase() == "building") {
			$(".dormitoryInput").hide();
			$(".filterForm :submit[name='submit']").removeAttr("disabled");
		}
	});
	
	$("#dormitoryName").blur(function() {
		var buildingId = $(":hidden[name='building']").val();
		var dormitoryName = $(this).val();
		var exist = checkDormitoryExist(buildingId, dormitoryName);
		if (dormitoryName != "") {
			if (!exist) {
				$(this).next().text("没有这个寝室");
				$(".filterForm :submit[name='submit']").attr("disabled", "disabled");
			} else {
				$(".filterForm :submit[name='submit']").removeAttr("disabled");
			}
		}
	}).focus(function() {
		$(this).next().text("");
	});
});